// pages/message/message.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    rightIcon: '/images/icon-right.png',
    message: [],
    page: 1,
    loadingHidden: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getMessage();
  },



  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      page: 1,
      message: [],
    })
    this.getMessage();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var page = that.data.page + 1;
    that.setData({
      page: page
    })
    that.getMessage();
  },

  /**
   * 公告详情
   */
  goMessageDetails: function (e) {
    var m_id = e.currentTarget.dataset.m_id;
    wx.navigateTo({
      url: '../messageDetails/messageDetails?m_id=' + m_id,
    })
  },



  getMessage() {
    var that = this;
    that.setData({
      loadingHidden: false
    })
    app.ajax({
      url: 'Partner/Console/message',
      data: {
        "page": that.data.page,
        "row": 150
      },
      success: function (res) {
        wx.stopPullDownRefresh()
        if (res.data.code == 1000) {
          let list;
          if (that.data.page == 1) {
            list = res.data.data.platform_bulletin
          } else {
            list = that.data.message.concat(res.data.data.platform_bulletin);
          }
          that.setData({
            message: list,
          })
        }
        if (res.data.data.platform_bulletin.length == 0) {
          app.showToast('没有更多了');
        }
      },
      error: e => {
        wx.stopPullDownRefresh()
      }
    })
  }
})